﻿@model IEnumerable<Kavaa.Modules.PortailMedical.Entity.Utilisateur>

@{
    ViewBag.Title = "ComptesCabinet";
    Layout = null;
}
@using System.Web.Optimization
@using BootstrapSupport
@using NavigationRoutes


        <script>


            $(function () {
                $("#submitbtn").click(function () {
                    $("#loading").fadeIn();
                    var opts = {
                        lines: 12, // The number of lines to draw
                        length: 7, // The length of each line
                        width: 4, // The line thickness
                        radius: 10, // The radius of the inner circle
                        color: '#000', // #rgb or #rrggbb
                        speed: 1, // Rounds per second
                        trail: 60, // Afterglow percentage
                        shadow: false, // Whether to render a shadow
                        hwaccel: false // Whether to use hardware acceleration
                    };
                    var target = document.getElementById('loading');
                    var spinner = new Spinner(opts).spin(target);
                });
            });




            //$.extend($.fn.dataTableExt.oStdClasses, {
            //    "sSortAsc": "header headerSortDown",
            //    "sSortDesc": "header headerSortUp",
            //    "sSortable": "header"
            //});

            ///* API method to get paging information */
            //$.fn.dataTableExt.oApi.fnPagingInfo = function (oSettings) {
            //    return {
            //        "iStart": oSettings._iDisplayStart,
            //        "iEnd": oSettings.fnDisplayEnd(),
            //        "iLength": oSettings._iDisplayLength,
            //        "iTotal": oSettings.fnRecordsTotal(),
            //        "iFilteredTotal": oSettings.fnRecordsDisplay(),
            //        "iPage": Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
            //        "iTotalPages": Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
            //    };
            //}
            //$.extend($.fn.dataTableExt.oStdClasses, {
            //    "sWrapper": "dataTables_wrapper form-inline"
            //});

            ///* Bootstrap style pagination control */
            //$.extend($.fn.dataTableExt.oPagination, {
            //    "bootstrap": {
            //        "fnInit": function (oSettings, nPaging, fnDraw) {
            //            var oLang = oSettings.oLanguage.oPaginate;
            //            var fnClickHandler = function (e) {
            //                if (oSettings.oApi._fnPageChange(oSettings, e.data.action)) {
            //                    fnDraw(oSettings);
            //                }
            //            };

            //            $(nPaging).addClass('pagination').append(
            //                '<ul>' +
            //                    '<li class="prev disabled"><a href="#">&larr; ' + oLang.sPrevious + '</a></li>' +
            //                    '<li class="next disabled"><a href="#">' + oLang.sNext + ' &rarr; </a></li>' +
            //                '</ul>'
            //            );
            //            var els = $('a', nPaging);
            //            $(els[0]).bind('click.DT', { action: "previous" }, fnClickHandler);
            //            $(els[1]).bind('click.DT', { action: "next" }, fnClickHandler);
            //        },

            //        "fnUpdate": function (oSettings, fnDraw) {
            //            var oPaging = oSettings.oInstance.fnPagingInfo();
            //            var an = oSettings.aanFeatures.p;
            //            var i, sClass, iStart, iEnd, iHalf = Math.floor(oPaging.iTotalPages / 2);

            //            if (oPaging.iTotalPages < 5) {
            //                iStart = 1;
            //                iEnd = oPaging.iTotalPages;
            //            }
            //            else if (oPaging.iPage <= iHalf) {
            //                iStart = 1;
            //                iEnd = 5;
            //            } else if (oPaging.iPage >= (5 - iHalf)) {
            //                iStart = oPaging.iTotalPages - 5 + 1;
            //                iEnd = oPaging.iTotalPages;
            //            } else {
            //                iStart = oPaging.iPage - Math.ceil(5 / 2) + 1;
            //                iEnd = iStart + 5 - 1;
            //            }

            //            for (i = 0, iLen = an.length ; i < iLen ; i++) {
            //                // Remove the middle elements
            //                $('li:gt(0)', an[i]).filter(':not(:last)').remove();

            //                // Add the new list items and their event handlers
            //                for (i = iStart ; i <= iEnd ; i++) {
            //                    sClass = (i == oPaging.iPage + 1) ? 'class="active"' : '';
            //                    $('<li ' + sClass + '><a href="#">' + i + '</a></li>')
            //                        .insertBefore('li:last', an[i])
            //                        .bind('click', function () {
            //                            oSettings._iDisplayStart = (parseInt($('a', this).text(), 10) - 1) * oPaging.iLength;
            //                            fnDraw(oSettings);
            //                        });
            //                }

            //                // Add / remove disabled classes from the static elements
            //                if (oPaging.iPage === 0) {
            //                    $('li:first', an[i]).addClass('disabled');
            //                } else {
            //                    $('li:first', an[i]).removeClass('disabled');
            //                }

            //                if (oPaging.iPage === oPaging.iTotalPages - 1) {
            //                    $('li:last', an[i]).addClass('disabled');
            //                } else {
            //                    $('li:last', an[i]).removeClass('disabled');
            //                }
            //            }

            //        }
            //    }
            //});
            $(document).ready(function () {
                $('#example').dataTable({
                    "sDom": "<'row'<'span4'l><'span4'f>r>t<'row'<'span4'i><'span4'p>>",
                    "sPaginationType": "bootstrap"
                });
            });



            ////////////////////////////////////////////////////////
            function ModifUser() {

                var elementselectionnee = new Array();
                var j = 0;
                var a = document.getElementsByName("selectedusers");
                for (i = 0; i < a.length ; i++) {
                    if (document.getElementsByName("selectedusers")[i].checked == true) {
                        elementselectionnee[j] = document.getElementsByName("selectedusers")[i];
                        j++;
                    }
                }
                if (j != 1) {
                    document.getElementById("popupBloquante").href = "#alert";
                    if (j == 0) {

                        document.getElementById("message").innerHTML = "Veuillez selectionner un element pour le modifier !!!";

                    }
                    if (j > 1) {

                        document.getElementById("message").innerHTML = "Veuillez sélectionner un seul élèment pour le modifier !!!";
                    }

                } else {
                    document.getElementById("popupBloquante").href = "#popup_Modification";

                    document.forms["modificatonForm"].elements["nom"].value = document.getElementById(elementselectionnee[0].value + " _nom").innerHTML;
                    document.forms["modificatonForm"].elements["prenom"].value = document.getElementById(elementselectionnee[0].value + " _prenom").innerHTML;
                    document.forms["modificatonForm"].elements["telephone"].value = document.getElementById(elementselectionnee[0].value + " _telephone").innerHTML;
                    document.forms["modificatonForm"].elements["fonction"].value = document.getElementById(elementselectionnee[0].value + " _fonction").innerHTML;
                    document.forms["modificatonForm"].elements["email"].value = document.getElementById(elementselectionnee[0].value + " _email").innerHTML;
                    document.forms["modificatonForm"].elements["idUtilisateur"].value = elementselectionnee[0].value;

                }


            }


            ////////////////////////////////////////////////////////

            function SuppUser() {

                var elementselectionnee = new Array();
                var j = 0;
                var a = document.getElementsByName("selectedusers");
                for (i = 0; i < a.length ; i++) {
                    if (document.getElementsByName("selectedusers")[i].checked == true) {
                        elementselectionnee[j] = document.getElementsByName("selectedusers")[i];
                        j++;
                    }
                }


                if (j == 0) {
                    document.getElementById("suppUserBtn").href = "#alert";
                    document.getElementById("message").innerHTML = "Veuillez selectionner un element pour le supprimer !!!";

                }
                else {

                    document.getElementById("suppUserBtn").href = "#popup_Delete";
                    document.getElementById("msgSupp").innerHTML = "Voulez vous vraiment supprimer les utilisateurs sélectionnés ?  ";
                }


            }
            /////////////////////////////////////////////////////////
            function tyty() {
                var elementselectionnee = new Array();
                var j = 0;
                var a = document.getElementsByName("selectedusers");
                for (i = 0; i < a.length ; i++) {
                    if (document.getElementsByName("selectedusers")[i].checked == true) {
                        elementselectionnee[j] = document.getElementsByName("selectedusers")[i];
                        j++;
                    }
                }

                $.ajax({
                    url: '/Cabinet/DeleteUtilisateur',//ça marche
                    async: false,
                    type: 'POST',
                    data: "selectedusers=" + elementselectionnee[0].value,
                    success: function () {
                        $('#a').attr('data-dismiss', 'modal');
                        alert("a");
                        $('#dd').load('/Cabinet/ComptesCabinet');
                        alert("load");
                    }
                });

                document.getElementById("InfoSelect").style.display = "block";
            }

            //**********************************************************

		</script>

      <!-- Example row of columns -->
   
<div>
   
    
      
     <div id="InfoSelect" class="alert alert-info" style="display:none">
                Vous devez sélectionner la spécialité et l'acte que vous voulez !!
          @*      <button type="button" class="close" data-dismiss="alert">&times;</button>*@
           </div>
    @*PopUp pour la création d'un nouveau utilisateur*@
 <div id="popup_Creation" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="popupLabel" aria-hidden="true" >
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="popupLabel2">Entrez les informations de l'utilisateur:</h3>
              </div>
                
                    @using (Html.BeginForm("CreerUser", "Cabinet","Post")){
                            @Html.AntiForgeryToken()
                            @Html.ValidationSummary(true)
  
                     <div style="padding-left:35px">
                          @Html.Action("CreerUser","Cabinet")
                     </div>
      
                   <div class="modal-footer">
                   <button class="btn" data-dismiss="modal" aria-hidden="true">Annuler</button>
                   <button class="btn btn-primary" type="submit"> Créer</button>
                  </div>
   
                    } 
 </div>
   
  

    @*PopUp pour la modification d'un utilisateur*@
     <div id="popup_Modification" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="popupLabel" aria-hidden="true"  >
				          <div class="modal-header">
					        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					        <h3 id="popupLabel2">Modifier un utilisateur</h3>
				          </div>
                        <form id="modificatonForm" action = "UpdateUser" method="get">

                                    <div style="padding-left:35px">
                                        <input type="hidden" name="idUtilisateur" value="" />
                                        <div> 
                                         <label>Nom</label>
                                            <input type="text" value="" name="nom" />
                                         </div>
                                         <div>
                                         <label>Prenom</label>
                                            <input type="text" value="" name="prenom" />
                                         </div>
                                        <div> 
                                         <label>Fonction</label>
                                            <input type="text" value="" name="fonction" />
                                         </div>
                                         <div>
                                         <label>Telephone</label>
                                            <input type="text" value="" name="telephone" />
                                         </div>
                                        <div>
                                         <label>Email</label>
                                            <input type="text" value="" name="email" />
                                         </div>
                                     </div>

                                         <div class="modal-footer">
							                 <button class="btn" data-dismiss="modal" aria-hidden="true">Annuler</button>
							                 <button class="btn btn-primary" type="submit" >Modifier</button>
							            </div>
                        </form>
                </div>

<div id="alert" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="popupLabel" aria-hidden="true"  >
				      <div class="modal-header">
					    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					    <h3 id="popupalert">Erreur bloquante</h3>
				      </div>
                      <div style="padding-left:35px">
                          <table>
                               <tr><th><br/></th></tr>
                               <tr><th><br/></th></tr>
                               <tr><th id="message"></th></tr>
                               <tr><th><br /></th></tr>
                               <tr><th><br/></th></tr>
                          </table>
                      </div>
                      <div class="modal-footer">
                           <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Retour</button>
                      </div>
                  </div>
@*Commentaire*@


 @*  @using (Html.BeginForm("DeleteUtilisateur","Cabinet","Post"))
 {  
     
          *@<div id="popup_Delete" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="popupLabel" aria-hidden="true" >
               <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                
              </div>
              <br /><br />
              <div id="msgSupp" style="padding-left:10px" > </div>
              <br /><br />
               <div class="modal-footer">
           <button class="btn" data-dismiss="modal" aria-hidden="true">Annuler</button>
           <button id="a" class="btn btn-primary" onclick="tyty()" name="buttons" value="supprimer" > Supprimer</button>
         
            </div>
              </div> 
     <br />
    <br />

<table class="table table-striped table-bordered" id="example" >
     <thead>
         <tr></tr> 
        <tr></tr>  
    <tr>
        
        <th style="width:10px"> </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Prenom)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Fonction)
        </th>
         <th>
            @Html.DisplayNameFor(model => model.Telephone)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Email)
        </th>
    </tr>
         </thead>
<tbody>
@foreach (var item in Model)
{
    <tr>
         <td style="text-align:center; vertical-align:middle"> <input type="checkbox" value= @item.Id name="selectedusers"/></td>
        <td id="@item.Id _nom">
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td id="@item.Id _prenom">
            @Html.DisplayFor(modelItem => item.Prenom)
        </td>
        <td id="@item.Id _fonction">
            @Html.DisplayFor(modelItem => item.Fonction)
        </td>
        <td id="@item.Id _telephone">
            @Html.DisplayFor(modelItem => item.Telephone)
        </td>
        <td id="@item.Id _email">
            @Html.DisplayFor(modelItem => item.Email)
        </td>
       
    </tr>
}
</tbody>
</table>
       
       

 @*}*@</div>    

   <div id="list"> </div>     



             <div id="dd"></div>

        
         @Scripts.Render("~/js")
       @*  @RenderSection("Scripts", required: false)*@
   
